﻿@page "/dialog/components-inside-dialog"

@using Syncfusion.Blazor.Popups;
@using Syncfusion.Blazor.Buttons;
@using Syncfusion.Blazor.Navigations;
@using Syncfusion.Blazor.Grids;
@using Syncfusion.Blazor.Schedule;
@using Syncfusion.Blazor.Charts;
@using Syncfusion.Blazor.RichTextEditor;
@using Syncfusion.Blazor.Calendars;
@using Syncfusion.Blazor.Inputs;
@using Pages.Schedule.Scheduler;
@inject NavigationManager NavigationManager
@using blazor_griddata;

@inherits SampleBaseComponent;

<SampleDescription>
    <p>
    This example demonstrates how to integrate other Blazor components within the dialog component. In the below example, The dialog component renders with the Grid, Schedule, Chart, Rich Text Editor, Tabs, and Form components.
    </p>
</SampleDescription>
<ActionDescription>
   <p>
    Since the dialog is container component, you can integrate other Blazor components within the dialog. The dialog can be rendered with simple plain-text, HTML string, or Blazor UI components. In the above sample, used major components such as Grid, Schedule, Chart, and Rich Text Editor inside dialog.
</p>
</ActionDescription>

<div class="col-lg-12 control-section" id="target">
    @if (@buttonVisible)
    {
        <SfButton Content="Open" OnClick="OnClick"></SfButton>
    }
    <SfDialog Width="700px" Height="400px" Target="#target" ShowCloseIcon="true" @bind-Visible="@dialogVisible">
        <DialogTemplates>
            <Header>
                Syncfusion Components inside Dialog
            </Header>
            <Content>
                <SfTab>
                    <TabItems>
                        <TabItem>
                            <ChildContent>
                                <TabHeader Text="Grid"></TabHeader>
                            </ChildContent>
                            <ContentTemplate>
                                <div>
                                    <SfGrid DataSource="@GridData" AllowPaging="true">
                                        <GridColumns>
                                            <GridColumn Field=@nameof(OrdersDetails.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
                                            <GridColumn Field=@nameof(OrdersDetails.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn>
                                            <GridColumn Field=@nameof(OrdersDetails.OrderDate) HeaderText="Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn>
                                            <GridColumn Field=@nameof(OrdersDetails.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
                                            <GridColumn Field=@nameof(OrdersDetails.ShipCountry) HeaderText="Ship Country" Width="150"></GridColumn>
                                        </GridColumns>
                                    </SfGrid>
                                </div>
                            </ContentTemplate>
                        </TabItem>
                        <TabItem>
                            <ChildContent>
                                <TabHeader Text="Schedule"></TabHeader>
                            </ChildContent>
                            <ContentTemplate>
                                <SfSchedule TValue="ScheduleData.AppointmentData" Width="100%" Height="650px" SelectedDate="new DateTime(2019, 1, 10)">
                                    <ScheduleEventSettings DataSource="@DataSource"></ScheduleEventSettings>
                                </SfSchedule>
                            </ContentTemplate>
                        </TabItem>
                        <TabItem>
                            <ChildContent>
                                <TabHeader Text="Chart"></TabHeader>
                            </ChildContent>
                            <ContentTemplate>
                                <SfChart Title="Inflation - Consumer Price" Theme="@Theme">
                                    <ChartArea><ChartAreaBorder Width="0"></ChartAreaBorder></ChartArea>
                                    <ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.DateTime" LabelFormat="yyyy" IntervalType="IntervalType.Years" EdgeLabelPlacement="EdgeLabelPlacement.Shift">
                                        <ChartAxisMajorGridLines Width="0"></ChartAxisMajorGridLines>
                                    </ChartPrimaryXAxis>
                                    <ChartPrimaryYAxis LabelFormat="{value}%" RangePadding="ChartRangePadding.None" Minimum="0" Maximum="100" Interval="20">
                                        <ChartAxisLineStyle Width="0"></ChartAxisLineStyle>
                                        <ChartAxisMajorTickLines Width="0"></ChartAxisMajorTickLines>
                                    </ChartPrimaryYAxis>
                                    <ChartTooltipSettings Enable="true"></ChartTooltipSettings>
                                    <ChartSeriesCollection>
                                        <ChartSeries DataSource="@ChartData" Name="Germany" XName="xValue" Width="2"
                                                     Opacity="1" YName="yValue" Type="ChartSeriesType.Line">
                                            <ChartMarker Visible="true" Width="10" Height="10">
                                            </ChartMarker>
                                        </ChartSeries>
                                        <ChartSeries DataSource="@ChartData" Name="England" XName="xValue" Width="2"
                                                     Opacity="1" YName="yValue1" Type="ChartSeriesType.Line">
                                            <ChartMarker Visible="true" Width="10" Height="10">
                                            </ChartMarker>
                                        </ChartSeries>
                                    </ChartSeriesCollection>
                                </SfChart>
                            </ContentTemplate>
                        </TabItem>
                        <TabItem>
                            <ChildContent>
                                <TabHeader Text="Rich Text Editor"></TabHeader>
                            </ChildContent>
                            <ContentTemplate>
                                <SfRichTextEditor>
                                    <ChildContent>
                                        <p>
                                            The Rich Text Editor component is WYSIWYG ("what you see is what you get") editor that provides the best user experience to create and update the content.
                                            Users can format their content using standard toolbar commands.
                                        </p>

                                        <p><b>Key features:</b></p>

                                        <ul>
                                            <li>
                                                <p>Provides <b>IFRAME</b> and <b>DIV</b> modes</p>
                                            </li>
                                            <li>
                                                <p>Capable of handling markdown editing.</p>
                                            </li>
                                            <li>
                                                <p>Contains a modular library to load the necessary functionality on demand.</p>
                                            </li>
                                            <li>
                                                <p>Provides a fully customizable toolbar.</p>
                                            </li>
                                            <li>
                                                <p>Provides HTML view to edit the source directly for developers.</p>
                                            </li>
                                            <li>
                                                <p>Supports third-party library integration.</p>
                                            </li>
                                            <li>
                                                <p>Allows preview of modified content before saving it.</p>
                                            </li>
                                            <li>
                                                <p>Handles images, hyperlinks, video, hyperlinks, uploads, etc.</p>
                                            </li>
                                            <li>
                                                <p>Contains undo/redo manager.</p>
                                            </li>
                                            <li>
                                                <p>Creates bulleted and numbered lists.</p>
                                            </li>
                                        </ul>
                                        <RichTextEditorToolbarSettings Items="@Tools" />
                                    </ChildContent>
                                </SfRichTextEditor>
                            </ContentTemplate>
                        </TabItem>
                        <TabItem>
                            <ChildContent>
                                <TabHeader Text="Forums"></TabHeader>
                            </ChildContent>
                            <ContentTemplate>
                                <div>
                                    <form method="post">
                                        <div id="formId" class="form-horizontal e-lib e-formvalidator">
                                            <div class="form-title"><span>Add Customer Details</span></div>
                                            <div class="form-group">
                                                <div class="e-float-input">
                                                    <SfTextBox Placeholder="User Name" FloatLabelType="FloatLabelType.Auto"></SfTextBox>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <div class="e-float-input">
                                                    <SfDatePicker TValue="DateTime" Placeholder="Date of Birth"></SfDatePicker>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <div class="e-float-input">
                                                    <SfTextBox Placeholder="Address" FloatLabelType="FloatLabelType.Auto" Multiline="true"></SfTextBox>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <div class="e-float-input">
                                                    <SfTextBox Placeholder="City" FloatLabelType="FloatLabelType.Auto" Multiline="true"></SfTextBox>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <div class="e-float-input">
                                                    <SfTextBox Placeholder="State" FloatLabelType="FloatLabelType.Auto"></SfTextBox>
                                                </div>
                                            </div>
                                            <div class="e-row">
                                                <div style="width: 220px;margin:0px auto;height: 100px;padding-top: 25px;">
                                                    <div style="display: inline-block;">
                                                        <button class="samplebtn e-control e-btn" type="submit" data-ripple="true">Add Customer</button>
                                                    </div>
                                                    <div style="float: right;">
                                                        <button class="samplebtn e-control e-btn" type="reset" data-ripple="true">Clear</button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </ContentTemplate>
                        </TabItem>
                    </TabItems>
                </SfTab>
            </Content>
        </DialogTemplates>
        <DialogAnimationSettings Effect="animationEffect"></DialogAnimationSettings>
        <DialogEvents Opened="OnOpen" Closed="OnClose"></DialogEvents>
        <DialogButtons>
            <DialogButton Content="Ok" IsPrimary="true" OnClick="OnBtnClick"></DialogButton>
            <DialogButton Content="Cancel" IsPrimary="true" OnClick="OnBtnClick"></DialogButton>
        </DialogButtons>
    </SfDialog>

</div>


@code {
    private string CurrentUri;


    bool buttonVisible { get; set; } = false;
    bool dialogVisible { get; set; } = true;
    private Syncfusion.Blazor.Theme Theme { get; set; }

    DialogEffect animationEffect = DialogEffect.None;

    public List<OrdersDetails> GridData { get; set; }

    public List<ScheduleData.AppointmentData> DataSource = new ScheduleData().GetScheduleData();

    public class LineChartData
    {
        public DateTime xValue { get; set; }
        public double yValue { get; set; }
        public double yValue1 { get; set; }
    }
    public List<LineChartData> ChartData = new List<LineChartData>
{
        new LineChartData { xValue = new DateTime(2005, 01, 01), yValue = 21, yValue1 = 28 },
        new LineChartData { xValue = new DateTime(2006, 01, 01), yValue = 24, yValue1 = 44 },
        new LineChartData { xValue = new DateTime(2007, 01, 01), yValue = 36, yValue1 = 48 },
        new LineChartData { xValue = new DateTime(2008, 01, 01), yValue = 38, yValue1 = 50 },
        new LineChartData { xValue = new DateTime(2009, 01, 01), yValue = 54, yValue1 = 66 },
        new LineChartData { xValue = new DateTime(2010, 01, 01), yValue = 57, yValue1 = 78 },
        new LineChartData { xValue = new DateTime(2011, 01, 01), yValue = 70, yValue1 = 84 },
    };

    private List<ToolbarItemModel> Tools = new List<ToolbarItemModel>()
{
        new ToolbarItemModel() { Command = ToolbarCommand.Bold },
        new ToolbarItemModel() { Command = ToolbarCommand.Italic },
        new ToolbarItemModel() { Command = ToolbarCommand.Underline },
        new ToolbarItemModel() { Command = ToolbarCommand.Separator },
        new ToolbarItemModel() { Command = ToolbarCommand.Formats },
        new ToolbarItemModel() { Command = ToolbarCommand.Alignments },
        new ToolbarItemModel() { Command = ToolbarCommand.OrderedList },
        new ToolbarItemModel() { Command = ToolbarCommand.UnorderedList },
        new ToolbarItemModel() { Command = ToolbarCommand.Separator },
        new ToolbarItemModel() { Command = ToolbarCommand.CreateLink },
        new ToolbarItemModel() { Command = ToolbarCommand.Image },
        new ToolbarItemModel() { Command = ToolbarCommand.Separator },
        new ToolbarItemModel() { Command = ToolbarCommand.SourceCode },
        new ToolbarItemModel() { Command = ToolbarCommand.Separator },
        new ToolbarItemModel() { Command = ToolbarCommand.Undo },
        new ToolbarItemModel() { Command = ToolbarCommand.Redo }
    };

    private void OnOpen()
    {
        this.buttonVisible = false;
    }

    private void OnClose()
    {
        this.buttonVisible = true;
    }

    private void OnBtnClick()
    {
        this.dialogVisible = false;
    }

    private void OnClick()
    {
        this.dialogVisible = true;
    }

    protected override void OnInitialized()
    {
        GridData = OrdersDetails.GetAllRecords();
        CurrentUri = NavigationManager.Uri;
        if (CurrentUri.IndexOf("material") > -1)
        {
            Theme = Syncfusion.Blazor.Theme.Material;
        }
        else if (CurrentUri.IndexOf("fabric") > -1)
        {
            Theme = Syncfusion.Blazor.Theme.Fabric;
        }
        else if (CurrentUri.IndexOf("bootstrap") > -1)
        {
            Theme = Syncfusion.Blazor.Theme.Bootstrap;
        }
        else if (CurrentUri.IndexOf("highcontrast") > -1)
        {
            Theme = Syncfusion.Blazor.Theme.HighContrast;
        }
        else
        {
            Theme = Syncfusion.Blazor.Theme.Bootstrap4;
        }
    }
}



<style>
    .control-section {
        padding-left: 10px;
    }

    #target {
        height: 100%;
        min-height: 520px;
    }

    @@media screen and (min-width: 150px) and (max-width: 480px) {
        .control-section {
            margin-bottom: 30px;
        }

        .control-wrapper {
            margin-bottom: 0px;
        }
    }

    #defaultDialog {
        top: 0% !important;
    }

    .e-btn-hide {
        display: none;
    }

    .form-title {
        text-align: center;
        padding: 10px;
        font-size: 16px;
        font-weight: 500;
        color: rgba(0, 0, 0, 0.70);
    }

    .e-error,
    .e-float-text {
        font-weight: 500;
    }

    .e-custom-label {
        font-size: 14px;
        font-weight: 500;
        margin-left: 20px;
    }

    #formId {
        padding-top: 10px;
        border: 1px solid #ccc;
        box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.36);
        border-radius: 5px;
        background: #f9f9f9;
        height: 267px;
        overflow-y: scroll;
    }

    .highcontrast form,
    .highcontrast .header {
        color: #fff;
        background: #000000;
    }

    .header {
        color: rgba(0, 0, 0, 0.7);
    }

    table,
    td,
    th {
        padding: 3px;
    }

    .form-horizontal .form-group {
        margin-left: 20px;
        margin-right: 20px;
        margin-bottom: 5px;
    }
</style>